from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-01-10 14:04:30.206935
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 10, Jan, 2022
Time: 14:04:35
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.6597
Nobs: 532.000 HQIC: -48.1000
Log likelihood: 6166.05 FPE: 9.71561e-22
AIC: -48.3832 Det(Omega_mle): 8.21639e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.397329 0.072605 5.472 0.000
L1.Burgenland 0.100503 0.043016 2.336 0.019
L1.Kärnten -0.113732 0.022171 -5.130 0.000
L1.Niederösterreich 0.177251 0.089450 1.982 0.048
L1.Oberösterreich 0.111699 0.088940 1.256 0.209
L1.Salzburg 0.270174 0.045367 5.955 0.000
L1.Steiermark 0.024968 0.059766 0.418 0.676
L1.Tirol 0.110127 0.048187 2.285 0.022
L1.Vorarlberg -0.077885 0.042588 -1.829 0.067
L1.Wien 0.005528 0.078740 0.070 0.944
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.061771 0.159361 0.388 0.698
L1.Burgenland -0.041612 0.094415 -0.441 0.659
L1.Kärnten 0.039874 0.048664 0.819 0.413
L1.Niederösterreich -0.209983 0.196334 -1.070 0.285
L1.Oberösterreich 0.454456 0.195215 2.328 0.020
L1.Salzburg 0.286554 0.099576 2.878 0.004
L1.Steiermark 0.114320 0.131179 0.871 0.383
L1.Tirol 0.307123 0.105765 2.904 0.004
L1.Vorarlberg 0.020429 0.093477 0.219 0.827
L1.Wien -0.023751 0.172825 -0.137 0.891
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.205224 0.037160 5.523 0.000
L1.Burgenland 0.092495 0.022016 4.201 0.000
L1.Kärnten -0.007621 0.011347 -0.672 0.502
L1.Niederösterreich 0.232908 0.045781 5.087 0.000
L1.Oberösterreich 0.162887 0.045520 3.578 0.000
L1.Salzburg 0.041120 0.023219 1.771 0.077
L1.Steiermark 0.023824 0.030588 0.779 0.436
L1.Tirol 0.083264 0.024662 3.376 0.001
L1.Vorarlberg 0.054417 0.021797 2.497 0.013
L1.Wien 0.112932 0.040299 2.802 0.005
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.129003 0.037145 3.473 0.001
L1.Burgenland 0.040115 0.022007 1.823 0.068
L1.Kärnten -0.014609 0.011343 -1.288 0.198
L1.Niederösterreich 0.167844 0.045763 3.668 0.000
L1.Oberösterreich 0.335314 0.045502 7.369 0.000
L1.Salzburg 0.105489 0.023210 4.545 0.000
L1.Steiermark 0.108565 0.030576 3.551 0.000
L1.Tirol 0.092612 0.024653 3.757 0.000
L1.Vorarlberg 0.054834 0.021788 2.517 0.012
L1.Wien -0.019783 0.040283 -0.491 0.623
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.098532 0.070546 1.397 0.163
L1.Burgenland -0.042242 0.041796 -1.011 0.312
L1.Kärnten -0.046114 0.021543 -2.141 0.032
L1.Niederösterreich 0.148445 0.086913 1.708 0.088
L1.Oberösterreich 0.173647 0.086418 2.009 0.044
L1.Salzburg 0.280710 0.044081 6.368 0.000
L1.Steiermark 0.061239 0.058071 1.055 0.292
L1.Tirol 0.154795 0.046820 3.306 0.001
L1.Vorarlberg 0.094397 0.041381 2.281 0.023
L1.Wien 0.080684 0.076507 1.055 0.292
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.097755 0.054828 1.783 0.075
L1.Burgenland 0.018820 0.032484 0.579 0.562
L1.Kärnten 0.051833 0.016743 3.096 0.002
L1.Niederösterreich 0.185629 0.067549 2.748 0.006
L1.Oberösterreich 0.327343 0.067164 4.874 0.000
L1.Salzburg 0.040246 0.034259 1.175 0.240
L1.Steiermark -0.004601 0.045132 -0.102 0.919
L1.Tirol 0.126161 0.036389 3.467 0.001
L1.Vorarlberg 0.063289 0.032161 1.968 0.049
L1.Wien 0.094679 0.059461 1.592 0.111
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.163747 0.066504 2.462 0.014
L1.Burgenland 0.009364 0.039401 0.238 0.812
L1.Kärnten -0.065685 0.020308 -3.234 0.001
L1.Niederösterreich -0.106644 0.081934 -1.302 0.193
L1.Oberösterreich 0.219756 0.081467 2.697 0.007
L1.Salzburg 0.050690 0.041555 1.220 0.223
L1.Steiermark 0.250315 0.054744 4.572 0.000
L1.Tirol 0.498906 0.044138 11.303 0.000
L1.Vorarlberg 0.064940 0.039010 1.665 0.096
L1.Wien -0.081417 0.072123 -1.129 0.259
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170348 0.073547 2.316 0.021
L1.Burgenland -0.006916 0.043574 -0.159 0.874
L1.Kärnten 0.063374 0.022459 2.822 0.005
L1.Niederösterreich 0.175439 0.090610 1.936 0.053
L1.Oberösterreich -0.068611 0.090094 -0.762 0.446
L1.Salzburg 0.207192 0.045956 4.509 0.000
L1.Steiermark 0.136505 0.060541 2.255 0.024
L1.Tirol 0.054557 0.048812 1.118 0.264
L1.Vorarlberg 0.144864 0.043141 3.358 0.001
L1.Wien 0.126078 0.079761 1.581 0.114
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.408249 0.042876 9.522 0.000
L1.Burgenland -0.004451 0.025402 -0.175 0.861
L1.Kärnten -0.020780 0.013093 -1.587 0.112
L1.Niederösterreich 0.198457 0.052823 3.757 0.000
L1.Oberösterreich 0.238206 0.052522 4.535 0.000
L1.Salzburg 0.037532 0.026791 1.401 0.161
L1.Steiermark -0.020320 0.035294 -0.576 0.565
L1.Tirol 0.088974 0.028456 3.127 0.002
L1.Vorarlberg 0.049880 0.025150 1.983 0.047
L1.Wien 0.027649 0.046498 0.595 0.552
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.032887 0.095435 0.158343 0.138602 0.081480 0.082425 0.025073 0.202997
Kärnten 0.032887 1.000000 -0.028053 0.132688 0.047706 0.083347 0.447825 -0.071102 0.093285
Niederösterreich 0.095435 -0.028053 1.000000 0.306472 0.126900 0.263339 0.065186 0.154525 0.275626
Oberösterreich 0.158343 0.132688 0.306472 1.000000 0.216166 0.289902 0.167132 0.132113 0.227958
Salzburg 0.138602 0.047706 0.126900 0.216166 1.000000 0.125220 0.081441 0.108737 0.127058
Steiermark 0.081480 0.083347 0.263339 0.289902 0.125220 1.000000 0.135563 0.102491 0.021379
Tirol 0.082425 0.447825 0.065186 0.167132 0.081441 0.135563 1.000000 0.065101 0.146360
Vorarlberg 0.025073 -0.071102 0.154525 0.132113 0.108737 0.102491 0.065101 1.000000 -0.008974
Wien 0.202997 0.093285 0.275626 0.227958 0.127058 0.021379 0.146360 -0.008974 1.000000